package com.tjsinfo.tjsoa.mail.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.PageController;
import com.tjsinfo.tjsoa.common.SessionUser;
import com.tjsinfo.tjsoa.mail.bo.ITjsDraftBo;
import com.tjsinfo.tjsoa.mail.bo.ITjsEmailFolderBo;
import com.tjsinfo.tjsoa.mail.vo.TjsDraft;
import com.tjsinfo.tjsoa.mail.vo.TjsEmailFolder;
/**
 * 查询草稿
 * @author wangxiaowei
 *
 */
public class SelectDrefEmailTitleAction extends Action{
	private ITjsDraftBo tjsDraftBo;
	private ITjsEmailFolderBo tjsEmailFolderBo;
	public ITjsEmailFolderBo getTjsEmailFolderBo() {
		return tjsEmailFolderBo;
	}
	public void setTjsEmailFolderBo(ITjsEmailFolderBo tjsEmailFolderBo) {
		this.tjsEmailFolderBo = tjsEmailFolderBo;
	}
	public ITjsDraftBo getTjsDraftBo() {
		return tjsDraftBo;
	}
	public void setTjsDraftBo(ITjsDraftBo tjsDraftBo) {
		this.tjsDraftBo = tjsDraftBo;
	}
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		List<TjsDraft> list =	tjsDraftBo.selectTitle(request.getParameter("title"), SessionUser.getUserId(request));//草稿列表
		Integer contentspage = null;
		String start = null;
		 PageController pageController = new PageController();
		    if(request.getParameter("page") != null && "".equals(request.getParameter("start")))
			{
				pageController.setPageController(list);
				pageController.setMaxPageRows(18);
				list = (ArrayList) pageController.getPageContents(Integer.parseInt(request.getParameter("page") ));
		
			}
		    else if (request.getParameter("page") != null) {
				contentspage = Integer.parseInt(request.getParameter("page"));
				start = request.getParameter("start");
				pageController.setPageController(list);
				pageController.setMaxPageRows(18);
				if (start.equals("up")) {
					list = (ArrayList) pageController
							.getPageContents(contentspage - 1);
				} else if(start.equals("down")) {
					list = (ArrayList) pageController
							.getPageContents(contentspage + 1);
				}
				else if(start.equals("first"))
				{
					list = (ArrayList) pageController
					.getPageContents(1);
				}
				else if(start.equals("last"))
				{
					list = (ArrayList) pageController
					.getPageContents(pageController.getPageCount());
				}
			} else {
				pageController.setPageController(list);
				pageController.setMaxPageRows(18);
				list = (ArrayList) pageController.getPageContents(1);
			}
		    List<TjsEmailFolder> list2 = tjsEmailFolderBo.selectByUserId(SessionUser.getUserId(request));
			request.setAttribute("foldlist", list2);
		request.setAttribute("pageController",pageController);
		request.setAttribute("list", list);
		request.setAttribute("title", request.getParameter("title"));
		return mapping.findForward("ok");
	}
	
}
